package com.itheima.advantagesup.mapper;

import com.github.pagehelper.Page;
import com.itheima.advantagesup.entity.SysUser;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * SysUserMapper
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/7/26 14:59
 */
@Mapper
public interface SysUserMapper {
    /**
     * 选择通过id
     *
     * @param id id
     * @return {@link SysUser}
     */
    SysUser selectById(String id);

    /**
     * 选择用户名
     *
     * @param loginName 登录名
     * @return {@link SysUser}
     */
    SysUser selectByUserName(String loginName);

    /**
     * 更新
     *
     * @param sysUser 系统用户
     */
    void updateById(SysUser sysUser);

    /**
     * 插入
     *
     * @param sysUser 系统用户
     */
    @Insert("insert into sys_user ( login_name, password, name, email, phone, login_ip, login_date, create_date, update_date, del_flag, role_id, status) " +
            "values (#{loginName},#{password},#{name},#{email},#{phone},#{loginIp},#{loginDate},#{createDate},#{updateDate},#{delFlag},#{roleId},#{status})")
    void insert(SysUser sysUser);

    /**
     * 删除通过id
     *
     * @param sysUser 系统用户
     */
    @Delete("delete from sys_user where id = #{id}")
    void deleteById(SysUser sysUser);

    /**
     * 选择列表
     *
     * @param sysUser 系统用户
     * @return {@link Page}<{@link SysUser}>
     */
    Page<SysUser> selectList(SysUser sysUser);

    /**
     * 选择数
     *
     * @return {@link Integer}
     */
    @Select("select COUNT(*) from sys_user;")
    Integer selectCount();
}
